#!/bin/bash
clear
if [[ "$EUID" -ne 0 ]]; then
  echo -e "\033[1;31m Anda tiada kebenaran untuk menjalankan skrip ini! \033[0m"; exit 1
fi

apt-get -qq update
apt-get -y -qq install shadowsocks-libev
apt-get -y -qq install simple-obfs
systemctl disable shadowsocks-libev
systemctl stop shadowsocks-libev

alamat_ip=$(wget -qO- ipv4.icanhazip.com)
alamat_hos=$(cat /etc/environment | grep -w 'DOMAIN' | cut -d '=' -f 2)
nama_pengguna=$(cat /etc/environment | grep -w 'USERNAME' | cut -d '=' -f 2)
kata_laluan=$(cat /etc/environment | grep -w 'PASSWORD' | cut -d '=' -f 2)

if [[ ! -d /etc/shadowsocks-libev/clients ]]; then
    mkdir -p /etc/shadowsocks-libev/clients
fi
touch /etc/shadowsocks-libev/.accounts

cat > /etc/shadowsocks-libev/server-default.json <<-EOF
{
    "server":"0.0.0.0",
    "server_port":6560,
    "local_port":1080,
    "password":"$kata_laluan",
    "method":"chacha20-ietf-poly1305",
    "mode":"tcp",
    "timeout":60,
    "fast_open":true,
}
EOF

cat > /etc/shadowsocks-libev/server-stunnel.json <<-EOF
{
    "server":"0.0.0.0",
    "server_port":6561,
    "local_port":1080,
    "password":"$kata_laluan",
    "method":"chacha20-ietf-poly1305",
    "mode":"tcp",
    "timeout":60,
    "fast_open":true,
}
EOF

systemctl enable shadowsocks-libev-server@server-default
systemctl start shadowsocks-libev-server@server-default
systemctl enable shadowsocks-libev-server@server-stunnel
systemctl start shadowsocks-libev-server@server-stunnel

echo
echo -e "\033[1;32m Pemasangan shadowsocks-libev pakej telah selesai. \033[0m"
echo